<template>
  <div>
    <el-breadcrumb>
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 添加按钮 -->
    <el-card>
      <el-row :gutter="20">
        <el-col :span="8">
          <!-- 搜索框 -->
          <el-input placeholder="请输入内容" clearable>
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" >添加商品</el-button>
        </el-col>
      </el-row>

      <!-- 表格区 -->
      <el-table :data="orderlist" boder stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否付款" prop="pay_status">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status === '1'"
              >已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"> </el-table-column>
        <el-table-column label="下单时间" prop="create_time">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFromate }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="showbox"
            ></el-button>
            <el-button
              type="success"
              icon="el-icon-share"
              size="mini"
              @click="shouprogess"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryinfo.pagenum"
        :page-sizes="[5, 10, 15]"
        :page-size="queryinfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      >
      </el-pagination>


      <!-- dilago对话框 -->
    <el-dialog
  title="修改地址"
  :visible.sync="dialogVisible"
  width="50%"
  @close="closethis"
  >
  <span>
   <el-form :model="addressForm" :rules="addressrules" ref="addressruleForm" label-width="100px" >
  <el-form-item label="省市区/县" prop="address1">
   <el-cascader
    v-model="addressForm.address1"
    :options="citydata"></el-cascader>
  </el-form-item>
    <el-form-item label="详细地址" prop="address2">
    <el-input v-model="addressForm.address2"></el-input>
  </el-form-item>
  </el-form>
  </span>
  <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
</el-dialog>
    </el-card>


  <!-- 展示物流对话框 -->
  <el-dialog
  title="物流进度"
  :visible.sync="editdialogVisible"
  width="50%">
  <el-timeline >
     <el-timeline-item
      v-for="(activity, index) in activities"
      :key="index"
      :timestamp="activity.timestamp">
      {{activity.content}}
    </el-timeline-item>
  </el-timeline>
</el-dialog>
  </div>
</template>

<script>
import citydata from './citydata'
export default {
  data() {
    return {
      queryinfo: {
        query: "",
        pagesize: 5,
        pagenum: 1,
      },
      total: 0,
      orderlist: [],
      dialogVisible:false,
      editdialogVisible:false,
      progessinfo:[],
      citydata,
      addressForm:{
        address1:[],
        address2:''
      },
       reverse: true,
        activities: [{
          content: '快递已从北京市出发',
          timestamp: '2018-04-15'
        }, {
          content: '通过检查站',
          timestamp: '2018-04-13'
        },{
          content: '快递发往成都',
          timestamp: '2018-04-11'
        },
        {
          content: '成都正在接受',
          timestamp: '2018-04-11'
        },
        {
          content: '快递从成都出发',
          timestamp: '2018-04-11'
        },
        {
          content: '快递已到目的地',
          timestamp: '2018-04-11'
        }
        ],
      addressrules:{
        address1:[{
        required:true,message:"请选择省市区县城",trigger:"blur"
      }],
       address2:[{
        required:true,message:"请输入详细地址",trigger:"blur"
      }],
      }
    };
  },
  created() {
    this.getorderlist();
  },
  methods: {
    async getorderlist() {
      const { data: res } = await this.$http.get("orders", {
        params: this.queryinfo,
      });
      if (res.meta.status != 200) {
        return this.$message.error("查询订单列表失败");
      }
      // this.$message.success("查询订单列表成功");
      this.total = res.data.total;
      this.orderlist = res.data.goods;
    },
    handleSizeChange(newsize) {
      this.queryinfo.pagesize = newsize;
      this.getorderlist();
    },
    handleCurrentChange(newpage) {
      this.queryinfo.pagenum = newpage;
      this.getorderlist();
    },
    showbox(){
  this.dialogVisible=true

    },
    closethis(){
      this.$refs.addressruleForm.resetFields();
    },
   async shouprogess(){
  //  const {data:res}= await this.$http.get("kuaidi/1106975712662")
  //  if(res.meta.status!==200) {return this.$message.error("获取物流信息失败")}
  //  this.$message.success("获取物流信息成功")
  //  this.progessinfo=res.data;
  //  console.log(res.data)
     this.editdialogVisible=true
    }
  }
};
</script>

<style lang="less" scoped></style>
